<?php
 function consultar_acce(){
    include (dirname(dirname(__FILE__)).'/Guardado/crearpdf2.php');
    include (dirname(dirname(__FILE__))."/accesobd.php");           
        
    $acce = "SELECT a.idacce, a.descripa, a.costo
                 FROM accesorio as a";
        $query1 = pg_query($conex,$acce);
    
    if(!$query1){
         echo '<script type="text/javascript">', 'window.alert("'.pg_last_error().'");',
                    'location.reload(true);'
                , '</script>'
             ;
    }
   else{
        //cabecera de la tabla
                    $cuerpo2.= "<img src='img/logo.png' /> <tr>
                        <td colspan='9' align='center'>CATALOGO DE ACCESORIOS</td></tr><table border=1 align='center' >
      
                        <thead>  
                        <tr>                               
                                <th>ID</th>
                                <th>Descripcion</th>
                                <th>Costo</th>            
                        </tr>
                      </thead>";?>
                     <thead>
                        <tr>
                                
                                <th>ID</th>
                                <th>Descripcion</th>
                                <th>Costo</th>    
                        </tr>
                        
                </thead>
                <?php
                while ($linea = pg_fetch_array($query1)) {
                    //Guardando tuplas en el pdf
                    $cuerpo2.= "
                        <tr>
                        <td>  ".$linea[0]."</td>
                        <td> ".$linea['descripa']."</td>
                        <td> ".$linea['costo']." </td>
                        </tr>";
                    ?>
                               
                    <tr>
                        <td <?php echo $linea[0]; ?></td>
                        <td> <?php echo $linea[1]; ?> </td>
                        <td> <?php echo $linea[2]; ?> </td>
                   </tr>
                <?php }
                 $cuerpo2.= "</table>";
                crear_pdf2($cuerpo2,'CatalogoAccesorios');
                
  
        // Redireccion
        pg_close($conex);
        }
 }

function consultar_veh(){

    include (dirname(dirname(__FILE__)).'/Guardado/crearpdf2.php');
    include (dirname(dirname(__FILE__))."/accesobd.php");   
          
    $vehiculos = "SELECT veh.idveh, veh.modelo, veh.marca, veh.np, veh.nc, veh.cap, veh.garantia, veh.seguro, veh.ffab, veh.lfab, veh.preciov, veh.peso, color.descp
                 FROM vehiculo as veh, color";
    $query = pg_query($conex,$vehiculos) or die('Consulta fallida: ' . pg_last_error());
        // Redireccion
        pg_close($conex);
        
     //cabecera de la tabla
                    $cuerpo.= "<img src='img/logo.png' /> <tr>
                        <td colspan='9' align='center'>CATALOGO DE VEHICULOS</td></tr><table border=1 >
      
                        <thead>  
                        <tr>
                                
                                <th>ID</th>
                                <th>Modelo</th>
                                <th>Marca</th>
                                <th>N° Puertas</th>
                                <th>N° Cilindros</th>
                                <th>Capacidad</th>
                                <th>Garantia</th>
                                <th>Seguro</th>
                                <th>Fecha de Fab.</th>
                                <th>Lugar de Fab.</th>
                                <th>Precio</th>
                                <th>Peso</th>
                                <th>Color</th>
                        </tr>
                      </thead>";?>
                     
                     <thead>
                        <tr>
                                
                                <th>ID</th>
                                <th>Modelo</th>
                                <th>Marca</th>
                                <th>N° Puertas</th>
                                <th>N° Cilindros</th>
                                <th>Capacidad</th>
                                <th>Garantia</th>
                                <th>Seguro</th>
                                <th>Fecha de Fab.</th>
                                <th>Lugar de Fab.</th>
                                <th>Precio</th>
                                <th>Peso</th>
                                <th>Color</th>
                        </tr>
                        
                </thead>
                <?php
                while ($linea = pg_fetch_array($query)) {
                    //Guardando tuplas en el pdf
                    $cuerpo.= "
                        <tr>
                        <td>  ".$linea['idveh']."</td>
                        <td> ".$linea['modelo']."</td>
                        <td> ".$linea['marca']." </td>
                        <td> ".$linea['np']." </td>
                        <td> ".$linea['nc']."</td>
                        <td> ".$linea['cap']." </td>
                        <td> ".$linea['garantia']."</td>
                        <td> ".$linea['seguro']."</td>
                        <td> ".$newDate = date("d-m-Y", strtotime($linea['ffab']))." </td> 
                        <td> ".$linea['lfab']." </td>
                        <td> ".$linea['preciov']."</td>
                        <td> ".$linea['peso']." </td>
                         <td>".$linea['descp']." </td>
                        </tr>";
                    ?>
                               
                    <tr>
                        <td <?php echo $linea['idveh'];?></td>
                        <td> <?php echo $linea[1];?> </td>
                        <td> <?php echo $linea[2];?> </td>
                        <td> <?php echo $linea[3];?> </td>
                        <td> <?php echo $linea[4];?> </td>
                        <td> <?php echo $linea[5];?> </td>
                        <td> <?php echo $linea[6];?> </td>
                        <td> <?php echo $linea[7];?> </td>
                        <td> <?php echo $newDate = date("d-m-Y", strtotime($linea[8])); ?> </td> 
                        <td> <?php echo $linea[9];?> </td>
                        <td> <?php echo $linea[10];?> </td>
                        <td> <?php echo $linea[11];?> </td>
                         <td> <?php echo $linea[12];?> </td></tr>
                <?php }
                 $cuerpo.= "</table>";
                
                crear_pdf2($cuerpo,'Catalogo');
                
      
  }

